
from typing import List


def addToArrayForm(num: List[int], k: int) -> List[int]:
    res =[]
    n = len(num)
    for i in range(n-1,-1,-1):
        sum_val = num[i] + k % 10
        k //=10
        if sum_val >= 10:
            k+=1
            sum_val -= 10
        res.append(sum_val)
    while k > 0:
        res.append(k%10)
        k//=10
    res.reverse()
    return res